/* ==============================================================================
 * 创 建 者：LYT
 * 创建日期：2018-03-14	
 * 功能描述：注册

 * 修 改 人:
 * 修改时间:
 * 修改描述：
 * ==============================================================================*/

//会员ID随机生成接口
//var getIDUrl = baseUrl + 'ApiOffLine/Register';
//注册接口
var registerUrl = baseUrl + 'DefaultF/RegeditSumbit';
//银行列表
var getBankListUrl = baseUrl + 'common/GetBankList';
//密保问题列表
var getQuestionListUrl = baseUrl + 'common/GetQuestionList';
//手机验证码
var getRegisterCodeUrl = baseUrl + 'DefaultF/RegisterCode';
//会员信息获取
var getMemberViewUrl = baseUrl + 'MemberF/MemberView';


var name = getURLParameter("refereeOID");
var vu;



$(function(){
	mui.init()
	initVue();
});

function initVue(){
	vu = new Vue({
		el: '#content',
		data: {
			member : '',
			RecommendName :'',
			Name :'',
			NiName :'',
			ParentName :'',
			LocationIndex :'',
			NewPassword :'',
			ConNewPassword :'',
			SecNewPassword :'',
			ConSecNewPassword :'',
			BankName :'',
			SubBranchBank :'',
			CardName :'',
			CardNumber :'',
			Tel :'',
			Question :'',
			Answer :'',
			ReportName : '',//报单中心
			
			IdentityCard:'',
			QuestionList:[],
			BankList:[],
			loadding: false,
		},
		mounted: function() {
//			this.getID();
			this.getBankList();
			this.getQuestionList();
			
			this.getMemberView();
		},
		methods: {
			getMemberView : getMemberView,
			getID : function(){
				common.get(getIDUrl, {}, '', function(r) {
					if(r.ErrorCode == 0) {
						vu.Name = r.Data.Name;
					} else {
						mui.toast(r.ErrorMsg);
					}
				})
			},
			register: function() {
				var _this = this;
				if(!this.Name) {
					mui.toast('请输入账号');
					return;
				};
				if(!this.Tel) {
					mui.toast('请输入手机号');
					return;
				};
				if(!this.RecommendName){
					mui.toast('请输入推荐人');
					return;
				}
				if(!this.NiName) {
					mui.toast('请输入昵称');
					return;
				};
				if(!this.ParentName) {
					mui.toast('请输入接点人账号');
					return;
				};
				if(!this.LocationIndex) {
					mui.toast('请选择接点位置');
					return;
				};
				if(!this.ReportName) {
					mui.toast('请输入报单中心');
					return;
				};
				if(!this.NewPassword) {
					mui.toast('请输入登陆密码');
					return;
				};
				if(!this.ConNewPassword) {
					mui.toast('请再次输入登陆密码');
					return;
				};
				if(this.NewPassword != this.ConNewPassword) {
					mui.toast('登陆密码输入不一致');
					return;
				};
				if(!this.SecNewPassword) {
					mui.toast('请输入安全密码');
					return;
				};
				if(!this.ConSecNewPassword) {
					mui.toast('请再次输入安全密码');
					return;
				};
				if(this.SecNewPassword != this.ConSecNewPassword) {
					mui.toast('两次安全密码输入不一致');
					return;
				};
				if(!this.BankName){
					mui.toast('请选择开户银行');
					return;
				}
				if(!this.SubBranchBank){
					mui.toast('请输入开户支行');
					return;
				}
				if(!this.CardName){
					mui.toast('请输入开户姓名');
					return;
				}
				if(!this.CardNumber){
					mui.toast('请输入银行卡号');
					return;
				}
				if(!this.Question){
					mui.toast('请选择密保问题');
					return;
				}
				if(!this.Answer){
					mui.toast('请输入密保答案');
					return;
				}
				
				vu.loadding = true;
				var param = {
					RecommendName : _this.RecommendName,
					Name : _this.Name,
					NiName : _this.NiName,
					ParentName : _this.ParentName,
					LocationIndex : _this.LocationIndex,
					NewPassword : _this.NewPassword,
					ConNewPassword : _this.ConNewPassword,
					SecNewPassword : _this.SecNewPassword,
					ConSecNewPassword : _this.ConSecNewPassword,
					BankName : _this.BankName,
					SubBranchBank : _this.SubBranchBank,
					CardName : _this.CardName,
					CardNumber : _this.CardNumber,
					ReportName : _this.ReportName,
					Tel : _this.Tel,
					Question : _this.Question,
					Answer : _this.Answer,
				}
				common.post(registerUrl, param, '', function(r) {
					vu.loadding = false;
					if(r.ErrorCode == 0) {
						mui.toast('注册成功!即将返回个人中心..');
						setTimeout(function () {
						    location.href = 'memberCenter.html';
						}, 1500);

					} else {
						mui.toast(r.ErrorMsg);
					}
				})
			},
			getQuestionList : function(){
				var _this = this;
				common.post(getQuestionListUrl, {}, '', function(r) {
					if(r.ErrorCode == 0) {
						_this.QuestionList = r.Data.List;
					} else {
						mui.toast(r.ErrorMsg);
					}
				})
			},
			getBankList : function(){
				var _this = this;
				common.post(getBankListUrl, {}, '', function(r) {
					if(r.ErrorCode == 0) {
						_this.BankList = r.Data.List;
					} else {
						mui.toast(r.ErrorMsg);
					}
				})
			}
		}
	})
}

function getMemberView(){
	common.get(getMemberViewUrl,{},'json',function(r){
		if(r.ErrorCode==0){
			vu.member = r.Data.member;
			
			if(r.Data.member.Name){
				vu.RecommendName = r.Data.member.Name;
				vu.ParentName = r.Data.member.Name;
			}
		}else{
			mui.toast(r.ErrorMsg);
		}
	})
}




/*
	VerificationCode: '',
	VerifyCode: '',
	validCode: true,
	ImageUrl: '',
	
	getTelphoneCode: function(e) {
		var _this = this;
		var code = $(e.target);
		if(!this.Tel) {
			mui.toast('请输入手机号');
			return;
		} else {
			var time = 60;
			common.post(RegisterCode, {Tel: _this.Tel}, 'json', function(r) {
				if(r.ErrorCode == 0) {
					if(_this.validCode) {
						_this.validCode = false;
						var t = setInterval(function() {
							time--;
							code.text(time + "秒");
							if(time == 0) {
								clearInterval(t);
								code.text("重新获取");
								_this.validCode = true;
							}
						}, 1000)
					}
				} else {
					mui.toast(r.ErrorMsg);
				}
			})
		}
	},
	getVerfication: function() {
		common.post(codeUrl, {}, 'json', function(r) {
			if(r.ErrorCode == 0) {
				vu.ImageUrl = r.Data.ImageUrl;
			} else {
				mui.toast(r.ErrorMsg);
			}
		})
	}
	
 */